// 定义记分牌类
class ScorePanel {
  // 分数登记
  score = 0;
  level = 1;

  // 分数登记元素
  scoreEle: HTMLElement;
  levelEle: HTMLElement;

  // 限制等级
  maxLevel: number;
  // 多少分升级
  upScore: number;

  constructor(maxLevel: number = 10, upScore: number = 10) {
    this.scoreEle = document.getElementById('score')!;
    this.levelEle = document.getElementById('level')!;
    this.maxLevel = maxLevel;
    this.upScore = upScore;
  }

  // 加分方法
  addScore() {
    // 分数自增
    this.scoreEle.innerHTML = ++this.score + '';
    // 判断分数
    this.score % this.upScore === 0 ? this.levelUp() : null;
  }

  // 提升等级方法
  levelUp() {
    this.level <= this.maxLevel ? this.levelEle.innerHTML = ++this.level + '' : null;
  }
}

export default ScorePanel;